package com.blt.car.me;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.blt.car.R;
import com.blt.car.base.BaseCommonAdapter;
import com.blt.car.base.BaseFragment;
import com.blt.car.base.ViewHolder;
import com.blt.car.utils.StringUtils;

import java.util.ArrayList;
import java.util.List;

import blt.app_core.api.base.CoreEvent;
import blt.app_core.api.base.CoreManager;
import blt.app_core.api.journey.JourneyApi;
import blt.app_core.api.journey.bean.Travel;
import blt.app_core.api.journey.bean.TravelOrder;

/**
 * 过路费明细
 * Created by xgp on
 * 2017/6/13.
 */

public class RoadCostFragment extends BaseFragment implements View.OnClickListener {

    private BaseCommonAdapter mAdapter;
    private ListView lvRoadCost;
    private List<TravelOrder> test;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_roadcost;
    }

    @Override
    protected void initData() {
        super.initData();
        CoreManager.getCore(JourneyApi.class).getTravel(1, 20,false,false);

    }

    @Override
    protected void initView(ViewHolder holder) {
        lvRoadCost = holder.get(R.id.lv_roadcost);
        test = new ArrayList<>();
        lvRoadCost.setAdapter(mAdapter = new BaseCommonAdapter<TravelOrder>(getContext(), test, R.layout.item_cost) {
            @Override
            public void showView(int position, View view, ViewGroup parent) {
                TextView startSite = (TextView) view.findViewById(R.id.item_road_from_site);
                TextView endSite = (TextView) view.findViewById(R.id.item_road_finish_site);
                TextView startTime = (TextView) view.findViewById(R.id.item_road_from_time);
                TextView endTime = (TextView) view.findViewById(R.id.item_road_finish_time);
                TextView no = (TextView) view.findViewById(R.id.item_road_no);
                TextView amount = (TextView) view.findViewById(R.id.item_road_amount);
                TravelOrder order = getItem(position);

                String start = order.start.split("-")[1];
                startSite.setText(start);
                String end = order.end.split("-")[1];
                endSite.setText(end);
                startTime.setText(StringUtils.getDays(order.startTime));
                endTime.setText(StringUtils.getDays(order.endTime));
                no.setText(order.carNo);
                amount.setText((int)order.amount + "元");

            }
        });
    }

    @CoreEvent(coreClientClass = JourneyApi.class)
    public void onTravel(Travel travel) {
        mAdapter.addAll(travel.travelOrderList);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

        }
    }
}
